/**
 * 
 */
package t4j.generics;

import java.util.ArrayList;
import java.util.Random;

import t4j.net.mindview.util.Generator;

//产品
class Product{
	private final int id;
	private String description;
	private double price;
	

	public Product(int IDnumber,String descr,double price) {
		id = IDnumber;
		description = descr;
		this.price = price;
		System.out.println(toString());
	}
	

	@Override
	public String toString() {		
		return id + ": "  + description + ", price: $" + price ;
	}
	
	public void priceChange(double change){
		price += change;
	}
	
	public static Generator<Product> generator = new Generator<Product>() {

		private Random rand = new Random(47);
		
		public Product next() {
		
			return new Product(rand.nextInt(1000), "Test", Math.round(rand.nextDouble() * 1000.0) + 0.99);
		}
		
	};
}

//货架
class Shelf extends ArrayList<Product>{

	public Shelf(int nProducts) {
		Generators.fill(this, Product.generator, nProducts);
	}
}

//通道
class Aisle extends ArrayList<Shelf>{
	
	public Aisle(int nShelves,int nProducts){
		
		for(int i = 0 ; i < nShelves; i++)//nShelves个通道一个货架
			add(new Shelf(nProducts));//一个货架nProducts个产品
	}
}

class CheckoutStand{}

//办公室
class Office{}

//商店
public class Store extends ArrayList<Aisle>{
	
	private ArrayList<CheckoutStand> checkouts = new ArrayList<CheckoutStand>();
	
	private Office office = new Office();
	
	
	public Store (int nAisles,int nShelves,int nProducts) {
		for(int i = 0 ; i < nAisles; i++)//nAisles个通道
			add(new Aisle(nShelves, nProducts));//一个通道nShelves个货架，nProducts个产品
	}
	

	@Override
	public String toString() {
		StringBuilder result = new StringBuilder();
		
		for(Aisle a : this)
			for(Shelf s : a)
				for(Product p : s){
					result.append(p);
					result.append("\n");
				}
		
		return result.toString();
	}
	
	public static void main(String[] args) {
		System.out.println(new Store(14, 5, 10));//14个通道，每个通道5个货架，每个货架10个产品
	}

}
